package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.sumpu.app.guoguojie.dao.ProductCategoryDao;
import cn.sumpu.app.guoguojie.domain.ProductCategory;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class ProductCategoryDaoImpl extends SqlSessionDaoSupport implements ProductCategoryDao {

	private static Logger logger = LoggerFactory.getLogger(ProductCategoryDaoImpl.class);

	@SuppressWarnings("unchecked")
	@Override
	public List<ProductCategory> getProductCategoryList(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return getSqlSession().selectList(
							"cn.sumpu.app.guoguojie.persistence.ProductCategoryMapper.getProductCategoryList",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Get market category list failure.", e);
			}
			throw new AppBusinessException("Get product category list failure.",
					e);
		}
	}

	@Override
	public ProductCategory getProductCategoryById(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return (ProductCategory) getSqlSession()
					.selectOne(
							"cn.sumpu.app.guoguojie.persistence.ProductCategoryMapper.getProductCategoryById",
							map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Get product category failure.", e);
			}
			throw new AppBusinessException("Get product category failure.", e);
		}
	}

	@SuppressWarnings("unchecked")
	public List<ProductCategory> getChildrenCategoryById(String paentCategoryId)
			throws AppBusinessException {
		try {
			return getSqlSession().selectList(
							"cn.sumpu.app.guoguojie.persistence.ProductCategoryMapper.getChildrenCategoryById",
							paentCategoryId);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("Get product category failure.", e);
			}
			throw new AppBusinessException("Get product category failure.", e);
		}
	}

}
